package demo15;
        /*查看指定URL的HTML源文档内容？
        提示：使用URL类和URLConnection类*/

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

public class test1 {
    public static void main(String[] args) {
        String spec = "http://www.kgc.cn/";
        BufferedReader reader = null;
        StringBuilder builder = new StringBuilder();
        try {
            URL url = new URL(spec);
            URLConnection conn = url.openConnection();

            reader = new BufferedReader(new InputStreamReader(conn.getInputStream(),"UTF-8"));
            String row = null;
            while((row = reader.readLine()) != null){
                builder.append(row);
                builder.append("\r\n");
            }
            System.out.println(builder.toString());
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if(reader != null){
                try {
                    reader.close();
                    reader = null;
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

    }
}
